package org.bluweb.g4wicket.orkut;

import java.util.HashMap;
import java.util.Map;

import org.bluweb.g4wicket.G4WicketComponent;


@SuppressWarnings("serial")
public class OrkutShare extends G4WicketComponent {

	private Map<String,String> options = new HashMap<String, String>();
	
	public static enum Style { REGULAR, MINI };
	
	public OrkutShare( String id ) {
		this( id, Style.REGULAR );
	}
	
	public OrkutShare( String id, Style style ) {
		super( id );
	}
	
	public OrkutShare setTitle( String title ) {
		return this.setOption( "title", title );
	}
	
	public OrkutShare setSummary( String summary ) {
		return this.setOption( "summary", summary );
	}

	public OrkutShare setThumbnailUrl( String url ) {
		return this.setOption( "thumbnail", url );
	}

	public OrkutShare setDestinationUrl( String url ) {
		return this.setOption( "destination", url );
	}	
	
	private OrkutShare setOption( String name, String value ) {
		this.options.put( name, value );
		return this;
	}

//  title:unescape('vxzcvxzv'),
//  summary:unescape('ggkg%20g%20lg%20'),
//  thumbnail:unescape('hgfjh%20hg%20l'),
//  destination:unescape('ghfhg%20gjhf%20')
	
	@Override
	protected void onBeforeRender() {
		super.onBeforeRender();
		
		Map<String,Object> parameters = new HashMap<String,Object>();
		parameters.put( "id", this.getId() );
		
		StringBuilder builder = new StringBuilder();
		for( String name : options.keySet() ) {
			builder.append( ',' );
			builder.append( name ).append( ":unescape('" );
			builder.append( options.get( name ) );
			builder.append( "')");
		}
		
		parameters.put( "options", builder.toString() );
		
		this.setJavaScriptTemplate( "OrkutShare.js", true, parameters );
	}
}
